const TitleEnd = "[header]:end";
const ContentEnd = "[content]:end";
const BackgroundImage = "./images/background.jpg";

function getQueryParameter(name) {
	var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
	var r = window.location.search.substr(1).match(reg);
	if (r != null) return r[2];
	return null;
}

var TempElement = document.createElement("p");
function encodeText(s) {
	document.createElement("p");
	(TempElement.textContent !== undefined) ? (TempElement.textContent = s) : (TempElement.innerText = s);
	return TempElement.innerHTML;
};

Bmob.initialize("803e4cc6ff3d9b2240ce2e9c58211613", "999891c4cba980a74e9585c803271856");

function setArticle(n) {
	$.ajax({
		type: 'get',
		url: 'articles/' + n + '.md',
		success: function (res) {
			var Content = document.getElementById("content");
			var en = res.indexOf(TitleEnd);
			var cen = res.indexOf(ContentEnd);
			var s = "";
			//s = "<header>" + marked(res.substring(0, en === -1 ? cen : en)) + "</header>";
			document.getElementById("TitleBanner").innerHTML += res.substring(0, en === -1 ? cen : en);
			if (en !== -1) s += ("<section>" + marked(res.substring(en + TitleEnd.length, cen === -1 ? res.length : cen)) + "</section>");
			Content.innerHTML = s;
			if (cen !== -1)
				eval(unescape(res.substring(cen + ContentEnd.length, res.length)));
			CurrentArticle = n;
		}
	});
}

CurrentArticle = '';
var rendererMD = new marked.Renderer();
marked.setOptions({
	renderer: rendererMD,
	gfm: true,
	tables: true,
	breaks: false,
	pedantic: false,
	sanitize: false,
	smartLists: true,
	smartypants: false
});
$(window).load(function () {
	window.body = $(document.body);
	var TitleBanner = $(".TitleBanner");
	var TitleHeight = TitleBanner.outerHeight();
	var HeaderHeight = window.innerHeight * 0.7;
	var Last = $(document).scrollTop();
	$(document).scroll(function () {
		var Height = $(this).scrollTop();
		if (Height > HeaderHeight) {
			TitleBanner.addClass("TitleBannerHide");
			TitleBanner.removeClass("TitleBannerTransparent");
			TitleBanner.addClass("TitleBannerNormal");
		} else {
			TitleBanner.removeClass("TitleBannerHide");
			TitleBanner.removeClass("TitleBannerNormal");
			TitleBanner.addClass("TitleBannerTransparent");
		}
		Last > Height ? TitleBanner.addClass("TitleBannerShow") : TitleBanner.removeClass("TitleBannerShow");
		Last = Height;
	});
});